<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Delete Contact</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>

<body>
<h4>Select Contact to Delete from System</h4>
<form action="#" method="post">
<select name="phone">
<option value="n/a">Select a Contact's Name to Delete</option>
<?php
$conn=mysql_connect("localhost","root","") or die("Could not Establish Connection".mysql_error());
$db=mysql_select_db("contacts_ms",$conn) or die("No DB Selected".mysql_error());
$cqry=mysql_query("SELECT * FROM info_contacts");
while($rw=mysql_fetch_array($cqry)){
	/*
	*This code selects the phone details that the user wants to delete from the database.
	*/?>
		<option value="<?php echo $rw['phone'] ?>"> <?php echo $rw['fname'].' '.$rw['sname'] ?></option> <?php
}
?>
</select><br/><br/>
<input type="submit" value="Delete Contact" name="submit" class="sbtns">&emsp;&emsp;&emsp;
<input type="reset" name="reset" value="Cancel" class="sbtns">
</form>
<?php
if(isset($_POST['submit'])){
	$phone=$_POST['phone'];
	//This code is for deleting the selected contact from the system as well as the particular grouping to the contact
	$dqry=mysql_query("DELETE FROM info_contacts WHERE phone='$phone'");
	$gqry=mysql_query("DELETE FROM group_contacts WHERE phone='$phone'");
	if(!$dqry && !$gqry) echo "Could not Delete Contact Successfully, please try again!";
	else echo "Contact Deleted Successfully from the System";
}
?>
</body>
</html>